' Dec to Bin
Function d2b(d As Single, Optional ib As String = "") As String
    Select Case d
    Case 1
        ib = "1" & ib
    Case 2
        ib = "10" & ib
    Case Else
        ib = (d Mod 2) & ib
        d2b Format(d / 2, "#"), ib
    End Select
    d2b = ib
End Function